package service

import (
	"awesomeProject/datamodles"
	"awesomeProject/repositories"
)

type IProductService interface {
	GetProductByID(productID int64) (*datamodles.Product, error)
	GetAllProduct() ([]*datamodles.Product, error)
	DeleteProduct(productID int64) bool
	InsertProduct(product *datamodles.Product) (int64, error)
	UpdateProduct(product *datamodles.Product) error
}

type ProductService struct {
	repo repositories.IProduct
}

func MewProductService(repo repositories.IProduct) IProductService {
	return &ProductService{repo: repo}
}

func (p ProductService) GetProductByID(productID int64) (*datamodles.Product, error) {
	return p.repo.SelectByKey(productID)
}

func (p ProductService) GetAllProduct() ([]*datamodles.Product, error) {
	return p.repo.SelectAll()
}

func (p ProductService) DeleteProduct(productID int64) bool {
	return p.DeleteProduct(productID)
}

func (p ProductService) InsertProduct(product *datamodles.Product) (int64, error) {
	return p.repo.Insert(product)
}

func (p ProductService) UpdateProduct(product *datamodles.Product) error {
	return p.repo.Update(product)
}
